package com.media.voice_rcd;

import java.io.IOException;

import android.media.MediaPlayer;
import android.media.MediaRecorder;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Environment;

public  class SoundPlayer {
	static final private double EMA_FILTER = 0.6;
	private static SoundPlayer soundPlayer = null;
	
	private MediaPlayer mMediaPlayer = new MediaPlayer();

	
	private SoundPlayer() {
	}

	public static SoundPlayer getInstance(){
		if (soundPlayer == null) {
			soundPlayer = new SoundPlayer();
		}
		return soundPlayer;
	}

	/**
	 * @Description
	 * @param path
	 */
	private void playMusic(String path) {
		try {
			if (mMediaPlayer == null) {
				mMediaPlayer = new MediaPlayer();
			}
			if (mMediaPlayer.isPlaying()) {
				mMediaPlayer.stop();
			}
			mMediaPlayer.reset();
			mMediaPlayer.setDataSource(path);
			mMediaPlayer.prepare();
			mMediaPlayer.start();
			mMediaPlayer.setOnCompletionListener(new OnCompletionListener() {
				public void onCompletion(MediaPlayer mp) {

				}
			});

		} catch (Exception e) {
			e.printStackTrace();
		}

	}


	public void stop() {
		if (mMediaPlayer != null) {
			if (mMediaPlayer.isPlaying()) {
				mMediaPlayer.stop();
			}
			mMediaPlayer = null;
		}
	}

	public void pause() {
		if (mMediaPlayer != null) {
			mMediaPlayer.pause();
		}
	}

	public void start() {
		if (mMediaPlayer != null) {
			mMediaPlayer.start();
		}
	}

}
